//
//  CustomCameraController.m
//  UIImagePickController
//
//  Created by DYS on 15/12/11.
//  Copyright © 2015年 DYS. All rights reserved.
//

#import "CustomCameraController.h"

@interface CustomCameraController ()<UIImagePickerControllerDelegate>
{
    UIImagePickerController *imagepicker;
}
@property (nonatomic,weak) UIImagePickerController *picker;

@property (nonatomic,weak) UIImageView *picture;

@end

@implementation CustomCameraController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    }
- (IBAction)takePhoto:(id)sender {
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 40)];
    titleLabel.backgroundColor = [UIColor blackColor];
    titleLabel.alpha = 0.5;
    titleLabel.text = @"呵呵哒~~~";
    titleLabel.textAlignment = 1;
    titleLabel.textColor = [UIColor whiteColor];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(20, 20, 80, 40);
    backBtn.backgroundColor = [UIColor blackColor];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.alpha = 0.5;
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    CGFloat x = (self.view.bounds.size.width - 80)/2;
    CGFloat y = self.view.bounds.size.height - 80 - 20;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(x, y, 80, 80);
    btn.clipsToBounds = YES;
    [btn setTitle:@"拍呀!" forState:UIControlStateNormal];
    btn.layer.cornerRadius = btn.frame.size.width / 2;
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *picture = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width - 100, y + 10, 60, 60)];
    self.picture = picture;
    picture.layer.borderWidth = 2;
    picture.layer.borderColor = [UIColor yellowColor].CGColor;
    
    //创建imagePickerController
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    self.picker = picker;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.navigationBarHidden = YES;
    picker.showsCameraControls = NO;//隐藏系统本身相机控件
    picker.delegate = (id)self;
    picker.allowsEditing = YES;
    //若要将相机铺满屏幕，可设置cameraViewTransform
    //将自定义控件加入相机视图
    //picker.cameraViewTransform = CGAffineTransformMakeScale(1, 2);
    picker.cameraCaptureMode
    [picker.cameraOverlayView addSubview:titleLabel];
    [picker.cameraOverlayView addSubview:backBtn];
    [picker.cameraOverlayView addSubview:btn];
    [picker.cameraOverlayView addSubview:picture];
    //进入相机界面
    [self presentViewController:picker animated:YES completion:nil];
}

-(void)back{
    [self.picker dismissViewControllerAnimated:YES completion:nil];
}
//拍照
-(void)click{
    [self.picker takePicture];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //这里只是简单获得图片，更多功能可自己实现
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.picture.image = image;
    
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    NSLog(@"点击了取消");
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
